#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>
void test()//exec族函数
{
  //execl("/bin/ls","ls","-a","l",NULL);
  char* const myargv[]={"/bin/ls","-a","-l",NULL};
  execv("/bin/ls",myargv);//用vector容器myargv替代全展开
  execlp("ls","ls","-a","-l",NULL);//path处只能放环境变量中包含的程序，第一个ls表示执行路径，第二个表示执行名称
  execvp("ls",myargv);
}


int main()//程序替换实例
{
  pid_t id=fork();
  if(id==0)
  {
    printf("子进程调用test\n");
    execl("/home/rxy/Process_concept/process_substitution/test","test",NULL);
    exit(-1);
  }
  sleep(3);
  int status=0; 
  printf("父进程执行，PID：%d\n",getpid());
  waitpid(id,&status,0);
  printf("子进程退出码为：%d\n",WEXITSTATUS(status));
  return 0;
}
